package com.hd123.rumba.gwt.widget2.client.grid.renderer;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.hd123.rumba.gwt.widget2.client.grid.RGrid;
import com.hd123.rumba.gwt.widget2.client.grid.RGridColumnDef;

/**
 * 图片渲染器工厂
 * 
 * @author LiQi
 * 
 */
public class RImageRendererFactory implements RCellRendererFactory {

  public RCellRenderer makeRenderer(final RGrid grid, final RGridColumnDef colDef, final int row,
      final int col) {
    Object data = grid.getProvider().getData(row - grid.getHeaderRowCount(), colDef.getIndex());
    final RImageRenderer result = new RImageRenderer();
    result.setValue(data);

    result.addClickHandler(new ClickHandler() {
      public void onClick(ClickEvent event) {
        grid.fireRGridClick(colDef, row, col, result);
      }
    });

    return result;
  }
}
